/*  This file is Copyright 2010 Hampton Smith
 * 
 *  This file is part of Adventure! a text-adventure game engine by Hampton
 *  Smith.
 *
 *  Adventure! is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Adventure! is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Adventure!.  If not, see http://www.gnu.org/licenses/.
 */

package edu.clemson.cs.hamptos.adventure;

import java.util.HashMap;

/**
 * <p>An <code>AdventureTarget</code> is an object that the player may interact
 * with.  It can be the "target" of a command, used as either the direct object
 * or the indirect object.  Examples of targets are doors (because they can
 * be targeted by commands like "go through door") and keys (because they
 * can be targeted by commands like "pick up key").</p>
 */
public interface AdventureTarget {

    /**
     * <p>Returns <code>true</code> if the given <code>text</code> is a valid
     * name for this target.  Used by the <code>Parser</code> to map textual
     * names to game objects.  As an example, a target representing a stone
     * gargoyle might be able to be referred to as a "gargoyle" or a "statue".
     * </p>
     *
     * @param text The text given by the user to refer to some object.
     *    Guaranteed to be non-null.
     *
     * @return <code>true</code> if this target may be referred to by the given
     *    text.
     */
    public boolean canBeReferredToAs(String text);

    /**
     * <p>Returns a short description of the object.  A word or three to remind
     * the player what it is.</p>
     *
     * @return The target's short description.
     */
    public String getShortDescription();

    /**
     * <p>A more complete description of the object than that given by
     * <code>getShortDescription()</code>.</p>
     *
     * @return The full description.
     */
    public String getDescription();

    /**
     * <p>Requests that this target attempt to process the given command as the
     * direct object of the command.  So, if the command given were
     * <code>"take key"</code>, the game engine would call this method to ask
     * that the key deal with being taken.  If this target does not understand
     * the command it's being asked to process, it will throw a
     * <code>DoNotUnderstandException</code>.</p>
     *
     * @param c The command the target is to process.
     * @param e The game engine, which this target may use to change the state
     *    of the game appropriately if it must in order to process the command.
     * @param w The input/output window, which this target may use to print
     *    text to the terminal if it must in order to process the command.
     *
     * @throws DoNotUnderstandException If this target does not know how to
     *    process the given command.
     */
    public void doCommandTo(AdventureCommand c, AdventureEngine e,
            AdventureWindow w) throws DoNotUnderstandException;

    /**
     * <p>Requests that this target attempt to process the given command as the
     * indirect object of the command.  So, if the command given were
     * <code>"unlock door with key"</code>, the game engine would call this
     * method to ask that the key deal with unlocking something.  If this target
     * does not understand the command it's being asked to process, it will
     * throw a <code>DoNotUnderstandException</code>.</p>
     *
     * @param c The command the target is to process.
     * @param e The game engine, which this target may use to change the state
     *    of the game appropriately if it must in order to process the command.
     * @param w The input/output window, which this target may use to print
     *    text to the terminal if it must in order to process the command.
     *
     * @throws DoNotUnderstandException If this target does not know how to
     *    process the given command.
     */
    public void doCommandWith(AdventureCommand c, AdventureEngine e,
            AdventureWindow w) throws DoNotUnderstandException;
    
    /**
     * <p>Checks to see if the verb can act on the <code>AdventureTarget</code>
     * as an indirect object, returns <code>true</code> if it can</p>
     * @param v
     * @return <code>true</code> if the operation is valid, <code>false</code> otherwise
     */
    public boolean checkVerbAsIO(String v);
    
    /**
     * <p>Checks to see if the verb can act on the <code>AdventureTarget</code>
     * as a direct object, returns <code>true</code> if it can</p>
     * @param v
     * @return <code>true</code> if the operation is valid, <code>false</code> otherwise
     */
    public boolean checkVerbAsDO(String v);
    
    /**
     * <p>Checks to see if the indirect object is acceptable to the 
     * <code>AdventureTarget</code>, returns <code>true</code> if it is</p>
     * @param v
     * @return <code>true</code> if the object is acceptable, <code>false</code> 
     *    otherwise
     */
    public boolean checkIO(String io);
    
    /**
     * <p>Gets the internal HashMap of stats for verb purposes only, be careful!</p>
     * @return the internal HashMap of stats
     */
    public HashMap<String, Integer> getStats();
    
    /**
     * <p>Gets the unique identifier of the <code>AdventureTarget</code></p>
     * @return the identifier as a String
     */
    public String getID();
    
    /**
     * <p>Clones the <code>AdventureTarget</code> by deep copying the fields</p>
     * @return 
     */
    public AdventureTarget clone();
    
    public void addListener(String target);
    
    public void removeListener(String target);
    
    public void notifyListeners(AdventureEngine e, AdventureWindow w);
    
    public void listen(AdventureEngine e, AdventureWindow w);

    public String getName();
}
